package it.mypofolio.model;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;

/**
 * @author  Paolo Cappelletti (Gempliss Srl)
 */
public class Portfolio {
	
	private List<Stock> stockList=new ArrayList<Stock>();
	private List<Done> doneList=new ArrayList<Done>();
	
	public void load(String path) throws ConfigurationException{
		XMLConfiguration config = new XMLConfiguration(path);
		int curr=0;
		while (config.getString("stock("+curr+").name")!=null){
			Stock currStock=new Stock(
					config.getString("stock("+curr+").name"),
					config.getString("stock("+curr+").sigla"),
					config.getInt("stock("+curr+").quantity"),
					config.getDouble("stock("+curr+").buyprice"),
					config.getDouble("stock("+curr+").buycommission"),
					config.getDouble("stock("+curr+").sellcommission")
			);
			stockList.add(currStock);
			curr++;
		}
		curr=0;
		while (config.getString("done("+curr+").name")!=null){
			Done currDone=new Done(
					config.getString("done("+curr+").name"),
					config.getDouble("done("+curr+").tot")
			);
			doneList.add(currDone);
			curr++;
		}	
	}

	public List<Stock> getStockList() {
		return stockList;
	}
	public List<Done> getDoneList() {
		return doneList;
	}
	
	
	

}
